package com.bolt.admin.module.sys.dto;

import com.bolt.admin.module.sys.entity.PrivilegeEntity;
import com.bolt.convention.data.BaseDTO;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MenuPrivilegeDTO extends BaseDTO {

    @NotNull(groups = {Update.class})
    private String id;

    @NotBlank
    private String title;

    @NotBlank
    private String code;

    private List<MenuDTO> children;
    @NotNull
    private Long pid;

    private Integer childrenSize = 0;

    private Integer subPrivilegeSize = 0;

    private Integer level;

    private String menuId;

    private PrivilegeEntity.PrivilegeTypeEnum type;


    public Boolean getIsLeaf() {
        if (this.type == PrivilegeEntity.PrivilegeTypeEnum.URL && this.pid != null) {
            children = subPrivilegeSize > 0 ? new ArrayList<>() : null;
            return !(subPrivilegeSize > 0);
        } else if (this.type == PrivilegeEntity.PrivilegeTypeEnum.BUTTON) {
            children = null;
            return true;
        } else {
            children = new ArrayList<>();
            return false;
        }
    }

}

 